
#ifndef __PIPEI_NOTIFY_H__
#define __PIPEI_NOTIFY_H__
#include "../iocp/IOCP/iocpdef.h"
#include "../iocp/IOCP/fileio.h"
#include "../utils/jsoncpp/json.h"
#include "../utils/jsoncpp/reader.h"
#include <string>

extern HIOCPBASE ghIocp;
#define PIPE_NAME TEXT("\\\\.\\pipe\\{13952DEE-9E4F-42D9-806F-F8E07CC58920}")

DWORD WINAPI NotifyThreadProc(LPVOID lpParam);

class CPipe {
public:
    CPipe();
    ~CPipe();

    static CPipe& GetInstan();

    BOOL Connect();
    BOOL IsConnect();
    BOOL IsLogin();
    BOOL Close();
    

    BOOL Login(HWND hWnd, LPCWSTR strAccess, LPCWSTR strPassword);
    BOOL Login(HWND hWnd, LPCSTR strAccess, LPCSTR strPassword);
    BOOL Logout();
    BOOL GetPolice();
    BOOL Test();

private:
    static void pipe_connect_cb(HIOCPFILE hObject, void* pUserData);
    static void pipe_read_cb(HIOCPFILE hObject, void* pUserData);
    static void pipe_write_cb(HIOCPFILE hObject, void* pUserData);
    static void pipe_signal_call(HIOCPFILE hObject, DWORD dwEvent, DWORD dwError);

    BOOL Write(const std::string& buffer);
    BOOL Write(const char* pBuffer, unsigned int uSize);

    void ConnectCallback();
    void WriteCallback();
    void ReadCallback();
    void SignalCallback(DWORD dwEvent, DWORD dwError);

    void Parse(Json::Value& root);
    void Clear();
    int m_msgsize;
    int m_offset;
    char m_buffer[4096];

    HWND m_hLoginWnd;
    BOOL m_bConnect;
    HIOCPFILE m_hPipe;
    std::string m_strAccess;
    std::string m_strPassword;
    std::string m_strToken;
    std::string m_strPolice;
};


#endif